/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.confirmForm;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import utils.SaisieUtils;

/**
 *
 * @author Paul
 */
public class ConfirmerSaisieNotes extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            this.doAny(request, response);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            this.doAny(request, response);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private void doAny(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String cours = request.getParameter("cours");
        String examen = request.getParameter("examen");
        String etudiant = request.getParameter("etudiant");
        String note = request.getParameter("note");
        if (!SaisieUtils.isNotEmptyField(note)) {
            request.setAttribute("message", "Veuillez sélectionner la note correspondante.");
            request.getRequestDispatcher("view/saisieNotes.jsp").forward(request, response);
        } else {
            /*
             * DAO
             */
            //Insérer la note de l'étudiant par rapport au cours et à l'examen
            request.setAttribute("message", "La note a été ajouté à l'étudiant.");
            request.getRequestDispatcher("view/associationCours.jsp").forward(request, response);
        }
    }
}
